<?php

namespace app\api\model;

use think\Model;

use app\api\model\Token;
use think\model\concern\SoftDelete;

/**
 * 代理商模型
 */
class Agent extends Model
{
    protected $deleteTime = 'delete_time';
    use SoftDelete;

    // protected $name='servers_user';
    protected $globalScope = ['block'];
    // 开启自动写入时间戳字段
    protected $auto_timestamp = 'false';
 
    public function scopeBlock($query)
    {
        $query->where('block',1);
    }

    public function getPhoneAttr($value) {
        return hidestr($value, 3, 4);
    }

    
    //用户登录
    public function UserLogin($mobile, $token, $event, $password)
    {
        $userToken = new Token(); 
        $is_exit = $this->where('phone', $mobile)->where('password', $password)->find();
        try {
            if ($is_exit) {
                $rst1 = $userToken->setToken($token, $is_exit['id'], $event);
                if ($rst1) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } catch (\Throwable $th) {
            return false;
        }
        return true;
    }
}
